package com.qing.emailservice.controller;


import com.qing.emailservice.entity.pojo.UcenterMember;
import com.qing.emailservice.entity.vo.LoginVo;
import com.qing.emailservice.entity.vo.RegisterVo;
import com.qing.emailservice.service.UcenterMemberService;
import com.qing.servicebase.utils.ResponseResult;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 会员表 前端控制器
 * </p>
 *
 * @author Yjx
 * @since 2022-09-14
 */
@RestController
@RequestMapping("/userservice/api/user")
@CrossOrigin(origins="*",maxAge=3600)
public class UcenterMemberController {

    private final UcenterMemberService ucenterMemberService;

    public UcenterMemberController(UcenterMemberService ucenterMemberService) {
        this.ucenterMemberService = ucenterMemberService;
    }

    //根据token字符串获取用户信息
    @PostMapping("/getInfoUc/{id}")
    public UcenterMember getInfo(@PathVariable String id) {
//根据用户id获取用户信息
        UcenterMember ucenterMember = ucenterMemberService.getById(id);
        UcenterMember memeber = new UcenterMember();
        BeanUtils.copyProperties(ucenterMember,memeber);
        return memeber;
    }

    @PostMapping(value = "/register")
    public ResponseResult register(@RequestBody RegisterVo registerVo){
        return ucenterMemberService.register(registerVo);
    }

    @PostMapping(value = "/login")
    public ResponseResult login(@RequestBody LoginVo loginVo){
        return ucenterMemberService.login(loginVo);
    }

    @GetMapping("/auth/getLoginInfo")
    public ResponseResult getLoginInfo(HttpServletRequest request){
        return  ucenterMemberService.getLoginInfo(request);
    }

    @GetMapping(value = "/countregister/{day}")
    public ResponseResult registerCount(@PathVariable String day){
        Integer count = ucenterMemberService.countRegisterByDay(day);
        return ResponseResult.ofSuccess(count);
    }

}

